var userAgent = navigator.userAgent;
var and_ios = "";
var ua = navigator.userAgent.toLowerCase();
var url = decodeURIComponent(window.location.href);
 // $("#dd").html(ua);


if (/iphone|ipad|ipod/.test(ua)) {
    //alert("iphone");   
    and_ios = "iphone";
} else if (/android/.test(ua)) {
    and_ios = "android";
}
if (ua.match(/MicroMessenger/i) == 'micromessenger' && and_ios == "iphone") {
    $('.iosweixin').show();
}

var trigger = false;
var trigger2 = false;
var trigger3 = false;
var trigger2 = 5;
var jishu1 = "";
var jishu2 = "";

function doShare(){
    var code = $("#biao").val();
    var pathName = window.document.location.pathname; 
    var pos = url.indexOf(pathName); 
    //获取主机地址，如： http://localhost:8080 
    var localhostPaht = url.substring(0,pos);
    var saveShareCode = genUrl("/app/saveShareCode");
    if(code){
        $.ajax({
            type : "GET",
            url : saveShareCode,
            data : {"code":code},
            dataType : "jsonp",
            async : false,
            jsonp : "jsonpCallback",
            beforeSend: function(xhr){ //发送请求前调用，可以放一些"正在加载"之类额话
                // xhr.setRequestHeader("x-access-id", shareId);
                // 加载层-默认风格
                layer.load();
                // layer.msg("正在加载……");
            },
            success: function (data) {   //成功后回调
                //此处演示关闭
                layer.closeAll('loading');
            },
            error: function(data){ //失败后回调
                //此处演示关闭
                layer.closeAll('loading');
            }
        });
    }else{
        // layer.msg('输入的手机号码不正确');
    }
}

$(function() {
    var paraString = url.substring(url.indexOf('=') + 1, url.length).split('&');
    var parameter=window.location.href.split("?")[1];
    // console.log(paraString);
    // $("#biao").val(paraString);
    $("#biao").val(getParameter("shareId"));
    var str = 'transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);';
    var mySwiper = new Swiper('.swiper-container', {
        speed: 500,
        direction: 'vertical',
        mousewheelControl: true,
        watchSlidesProgress: !0,
        onSlideChangeStart: function(swiper) {
            var activeIndex = swiper.activeIndex;
            console.log(activeIndex)
            if (activeIndex == 4) {
                $('.infoOne').hide();
                $('.twopart').show();
            }
        },
        onSlideChangeEnd: function(swiper) {
            var activeIndex = swiper.activeIndex;
            console.log(activeIndex)
            if (activeIndex == 4) {}
        }
    });
    $('.ck').height($(window).height());
    $('.swiper-slide05').height($(window).height());
    /**
     * 是否在微信qq内置浏览器
     * @returns {boolean}
     */
    var isTengxun = function(){
        var ua = navigator.userAgent.toLowerCase();
        // if(ua.match(/MicroMessenger/i)=="micromessenger"||ua.match(/WeiBo/i) == "weibo" || ua.match(/qbwebviewtype/i) == "qbwebviewtype") {
        //     return true;
        // }else if(ua.indexOf('mobile mqqbrowser')>-1){
        //     return true;
        // } else if(ua.indexOf('iphone') > -1 || ua.indexOf('mac') > -1){
        //     if(ua.indexOf('qq') > -1){
        //         return true;
        //     }
        // }
        // return false;
        if(ua.match(/MicroMessenger/i)=="micromessenger"||ua.match(/WeiBo/i) == "weibo" || ua.match(/qq\//i) == "qq/") {
            return true;
        }
        return false;
    }
    //微信判断
    function isWeiXin() {
        if (ua.match(/MicroMessenger/i) == 'micromessenger') {
            return true;
        } else {
            return false;
        };
    };

    //微信判断
    var weixinDownLoad = "http://a.app.qq.com/o/simple.jsp?pkgname=com.ms.flowerlive";
    var androidDownLoad = "http://a.app.qq.com/o/simple.jsp?pkgname=com.ms.flowerlive";
    var iosDownLoad1 = "https://itunes.apple.com/app/id1277470059";
    var shareId=getParameter("shareId");
    var heightVal = "";
    var wWidth = $(window).width();
    if (wWidth <= 320) {
        heightVal = -2000;
    } else if (wWidth <= 375) {
        heightVal = -2300;
    } else {
        heightVal = -2500;
    };
    $('.xzlct').click(function(event) {
        // if(isTengxun()){
        //     $(".zhezhao").show();
        //     return;
        // }else{
        //     var hostname = window.document.location.hostname;
        //     if ("www.huakai.me" == hostname){
        //        // window.open("http://cdn.download.huakai.me/app-release_v28_1.5.5_1.apk");
        //     }else {
        //        // window.open("http://cdn.download.huakai.me/app-debug_v1.5.6.apk");
        //     }
        // }
        // if (isTengxun()) {
        //   // $('.xzlct').attr('href', weixinDownLoad);
        //     doShare();
        // } else {
            if (and_ios == "iphone") {
                if(isTengxun()) {
                    $(".zhezhao").show();
                    return;
                }
                // $('.xzlct').attr('href', iosDownLoad1);
                $('.xzlct').attr('href', "../app/workspace/guide/index.html?"+parameter);

                doShare();
                mySwiper.appendSlide('<div class="swiper-slide swiper-slide05"><img src="/static/img/sm02.png" class="bigimg01"> </div>');
                $('.infoOne').hide();
                $('.twopart').show();
                mySwiper.on('onTouchEnd', function(swiper) {
                    var activeIndex = swiper.activeIndex;
                    console.log(activeIndex)
                    if (activeIndex == 4) {
                        $('.infoOne').hide();
                        at.to(3);
                        $('.twopart').show();
                    }
                });
            }else {
                //   ShareInstall第三方库（和第九版一起发布）
                var data = ShareInstall.parseUrlParams();//shareinstall.js中提供的工具函数，解析url中的所有查询参数
                data.appkey="BABK7E6KAKBEFH";
                var shareSdk = new ShareInstall({
                    appKey : 'BABK7E6KAKBEFH',
                    onready : function() {// 回调成功
                        var m = this;
                        m.schemeWakeup();
                        m.wakeupOrInstall();
                    }
                }, data);

                // $('.xzlct').attr('href', androidDownLoad);
                // doShare();
            }
        // };
    });

    //$('.bigimg02').click(function(event) {
    $('.main_lct_show').on('click', '.bigimg02', function(event) {
        $('.twopart').hide();
        mySwiper.slideTo(0, 1000, false); //切换到第一个slide，速度为1秒
        $('.infoOne').show();
        at.to(3);

    });
    /**/
    var target = document.querySelector("#scroller");
    Transform(target, true);
    var at = new AlloyTouch({
        touch: "#wrapper", //反馈触摸的dom
        vertical: true, //不必需，默认是true代表监听竖直方向touch
        target: target, //运动的对象
        property: "translateY", //被滚动的属性
        sensitivity: 1, //不必需,触摸区域的灵敏度，默认值为1，可以为负数
        factor: 1, //不必需,默认值是1代表touch区域的1px的对应target.y的1
        min: heightVal, //不必需,滚动属性的最小值
        max: 0, //不必需,滚动属性的最大值
        step: 40,
        change: function(v) {

        },
        animationEnd: function(value) {

            if (value == 0) {
                $('.twopart').hide();
                mySwiper.slideTo(3, 400, false); //切换到第一个slide，速度为1秒
                $('.infoOne').show();
                $('.swiper-slide05').show();
            }
        },
        pressMove: function(evt, value) {

        }
    });
    document.addEventListener("touchmove", function(evt) {
        evt.preventDefault();
    }, false);
    /**/
    //注册人数
    /*$.ajax({
        type: "get",
        async: false,
        url: 'http://www.ipaychat.com/index!queryTotalNum.jhtml',
        data: {},
        dataType: "jsonp",
        jsonp: "callback",
        jsonpCallback: "totalNumCallback",
        success: function(data) {
            // console.log(data);
            var dataInfo = data;
            if (dataInfo.resultCode == 1000) {
                var num = dataInfo.info.num;
                $('#myTargetElement').html(num);
                //CountUp
                var options = {  
                    useEasing: true,
                      useGrouping: true,
                      separator: ',',
                      decimal: '.',
                      prefix: '',
                      suffix: ''
                };
                var demo = new CountUp("myTargetElement", 0, num, 0, 1.5, options);
                demo.start();
                //CountUp                
            }
        },
        error: function(error) {
            console.log('fail');
        }
    });*/
    //注册人数

    var clipboard = new Clipboard(".xzlct");
    // clipboard.destroy();

    clipboard.on("success",function (element) {//复制成功的回调
       // alert("复制成功");
    });

    clipboard.on("error",function (element) {//复制失败的回调
        // clipboard.destroy();
    });

    var clipboardInvite = new Clipboard(".a_invite_copy");
    clipboardInvite.on("success",function (element) {//复制成功的回调
        alert("复制成功");
    });
    clipboardInvite.on("error",function (element) {//复制失败的回调
        // clipboard.destroy();
    });

});
